package binarysearch;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Solution {
    public static int[] stringToIntegerArray(String input) {
        input = input.trim();
        input = input.substring(1, input.length() - 1);
        if (input.length() == 0) {
            return new int[0];
        }

        String[] parts = input.split(",");
        int[] output = new int[parts.length];
        for(int index = 0; index < parts.length; index++) {
            String part = parts[index].trim();
            output[index] = Integer.parseInt(part);
        }
        return output;
    }

    // 查找第一个值等于给定值的元素
    // [-9,9,9,9,9,9,10] target = 9, return 1
    public int searchSecendValue(int[] nums, int target) {
        int i = 0, j = nums.length - 1;
        int pivot;
        while(i <= j) {
            pivot = i + j >> 1;
            // 先满足基本条件，等于给定值
            if(nums[pivot] == target) {
                // 再满足是否是第一个值
                if(pivot == 0 || nums[pivot - 1] < target) {
                    return pivot;
                }
                j = pivot - 1;
            }else if(nums[pivot] > target) j = pivot - 1;
            else if(nums[pivot] < target) i = pivot + 1;
        }
        return -1;
    }

    // 查找最后一个值等于给定值的元素
    // [-9,9,9,9,9,9]
    public int searchLastValue(int[] nums, int target) {
        int l = 0, r = nums.length - 1;
        int pivot;
        while(l <= r) {
            pivot = l + r >> 1;
            if(nums[pivot] == target) {
                if (pivot == nums.length - 1 || nums[pivot + 1] > target) {
                    return pivot;
                }
                l = pivot + 1;
            }
            else if(nums[pivot] > target) r = pivot - 1;
            else l = pivot + 1;
        }
        return -1;
    }

    // 搜索第一个大于等于给定值的元素
    // [-9,9,9,9,9,9]
    public int searchFirstGreaterThanOrEqualTo(int[] nums, int target) {
        int l = 0, r = nums.length - 1;
        int pivot = 0;
        while(l <= r) {
            pivot = l + ((r - l) >> 1);
            if(nums[pivot] < target) l = pivot + 1;
            // 先满足最基本的条件，大于等于
            else {
                // 再判断是否是第一个
                if(pivot == 0 || nums[pivot - 1] < target) return pivot;
                r = pivot - 1;
            }
        }
        return -1;
    }

    // 查找最后一个小于等与给定值的元素
    // [-9,8,8,8,9,9,9,9,10] target = 1 return 1
    public int searchLastLessThanOrEqualTo(int[] nums, int target) {
        int l = 0, r = nums.length - 1, pivot = 0;
        while(l <= r) {
            pivot = l + ((r - l) >> 1);
            if (nums[pivot] > target) r = pivot - 1;
            else {
                if (pivot == nums.length - 1 || nums[pivot + 1] > target) return pivot;
                l = pivot + 1;
            }
        }
        return -1;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            int[] nums = stringToIntegerArray(line);
            line = in.readLine();
            int target = Integer.parseInt(line);

            int ret = new Solution().searchLastLessThanOrEqualTo(nums, target);

            String out = String.valueOf(ret);

            System.out.print(out);
        }
    }
}